<?php

class Data {
    var $color;
    var $size;
    function Data () {
        $this->color='white';
        $this->size='medium';
    }
    function getColor() {
        return $this->color;
    }
    function getSize () {
        return $this->size;
    }
    function setColor ($color) {
        $this->color=$color;
    }
    function setSize ($size) {
        $this->size=$size;
    }
}

class ControlPanel {
    var $data; // An instance of the Data class
 
    // Receive a reference to an instance of Data
    function ControlPanel (& $data) {
        $this->data=& $data; // Pass by reference again
    }
    function changeColor ($color) {
        $this->data->setColor($color);
    }
    function changeSize ($size) {
        $this->data->setSize($size);
    }

class Output  {
    var $data; // An instance of the Data class
    var $output;
    function Output ($data) {
        $this->data=$data; // Copy the instance of Data
    }
    function buildOutput () {
        $this->output='Color is '.$this->data->getColor().
            ' and size is '.$this->data->getSize();
    }
    function display () {
        $this->buildOutput();
        return $this->output;
    }
}

$data=new Data; // Create an instance of Data
$output=new Output ($data); // Pass it to an instance of Output

// Use ControlPanel to modify some settings
$cp= new ControlPanel($data);
$cp->changeColor('red');
$cp->changeSize('large');

// Display the output
echo ($output->display()); 


?>
